/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package dao;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.Statement;

/**
 *
 * @author Tadeu Augusto
 */
public class Conexao {

    public static Connection getConnection() throws PortalDAOException {
        try {
            Class.forName("org.postgresql.Driver");
            String bd = "jdbc:postgresql://localhost/GlobalSource";
            String usr = "postgres";
            String pswrd = "grupo5pw";
            return DriverManager.getConnection(bd, usr, pswrd);
        } catch (Exception e) {
            throw new PortalDAOException(e.getMessage());
        }
    }
    
    public static void closeConnection(Connection conn, Statement stat, ResultSet rs)throws PortalDAOException{
        close(conn, stat, rs);
    }
    
    public static void closeConnection(Connection conn, Statement stat)throws PortalDAOException{
        close(conn, stat, null);
    }
    
    public static void closeConnection(Connection conn)throws PortalDAOException{
        close(conn, null, null);
    }
    
    private static void close(Connection conn, Statement stat, ResultSet rs)throws PortalDAOException{
        try {
            if(conn != null) conn.close();
            if(stat != null) stat.close();
            if(rs != null) rs.close();
        } catch (Exception e) {
            throw new PortalDAOException(e.getMessage());
        }
    }
}
